﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DAO
{
   public  class LensDAO
    {
        CameraDBEntities db = new CameraDBEntities();
        public List<Lens> GetListAll()
        {
            return db.Lenses.Where(x => x.lensStatus == true).ToList();
        }
        public List<Lens> GetListTop10()
        {
            return db.Lenses.Where(x => x.lensStatus == true).Take(10).ToList();
        }
        public Lens GetById(int id)
        {
            return db.Lenses.Where(x => x.lensId == id && x.lensStatus == true).SingleOrDefault();
        }

        public List<Lens> GetListSearch(string tukhoa)
        {
            List<Lens> listkq = new List<Lens>();
            listkq = db.Lenses.Where(x => x.lensStatus == true).ToList();
            listkq = listkq.FindAll(

                delegate(Lens math)
                {
                    if (Utils.ConvertToUnSign(math.lensNames.ToLower()).Contains(tukhoa))
                        return true;
                    else
                        return false;
                }
            );
            return listkq;
        }
    }
}
